import { describe, it, expect } from 'vitest';
import type { 
  ApiResponse, 
  LoginResponse, 
  MenuItem, 
  Agent, 
  UserInfo 
} from '../api';

describe('API Types', () => {
  describe('ApiResponse', () => {
    it('should have correct structure', () => {
      const response: ApiResponse<string> = {
        code: 0,
        msg: 'success',
        data: 'test data'
      };
      
      expect(response.code).toBe(0);
      expect(response.msg).toBe('success');
      expect(response.data).toBe('test data');
    });

    it('should support optional data field', () => {
      const response: ApiResponse = {
        code: 500,
        msg: 'error'
      };
      
      expect(response.code).toBe(500);
      expect(response.msg).toBe('error');
      expect(response.data).toBeUndefined();
    });
  });

  describe('LoginResponse', () => {
    it('should have correct login response structure', () => {
      const loginData: LoginResponse = {
        token: 'abc123',
        expire: 3600,
        userInfo: {
          userId: 1,
          username: 'admin',
          nickName: 'Administrator'
        }
      };
      
      expect(loginData.token).toBe('abc123');
      expect(loginData.expire).toBe(3600);
      expect(loginData.userInfo?.username).toBe('admin');
    });
  });

  describe('MenuItem', () => {
    it('should support nested menu structure', () => {
      const menu: MenuItem = {
        id: '1',
        name: 'dashboard',
        path: '/dashboard',
        title: '仪表盘',
        icon: 'dashboard-icon',
        children: [
          {
            id: '1-1',
            name: 'analytics',
            path: '/dashboard/analytics',
            title: '数据分析'
          }
        ]
      };
      
      expect(menu.children).toHaveLength(1);
      expect(menu.children?.[0].title).toBe('数据分析');
    });
  });

  describe('Agent', () => {
    it('should have correct agent structure', () => {
      const agent: Agent = {
        id: '1',
        name: 'GPT-4',
        keyStr: 'sk-abc123',
        addr: 'https://api.openai.com',
        description: 'OpenAI GPT-4 model'
      };
      
      expect(agent.name).toBe('GPT-4');
      expect(agent.keyStr).toBe('sk-abc123');
      expect(agent.addr).toBe('https://api.openai.com');
    });
  });

  describe('UserInfo', () => {
    it('should have correct user info structure', () => {
      const user: UserInfo = {
        userId: 1,
        username: 'admin',
        nickName: 'Administrator',
        email: 'admin@example.com',
        roles: [
          {
            roleId: 1,
            roleName: '管理员',
            roleKey: 'admin'
          }
        ],
        permissions: ['user:read', 'user:write']
      };
      
      expect(user.userId).toBe(1);
      expect(user.roles).toHaveLength(1);
      expect(user.permissions).toContain('user:read');
    });
  });
});